package com.dg.cuckoo.admin.action.basicInformation;

import com.dg.cuckoo.admin.dto.basicInformation.projectInformation.BasicProjectDto;
import com.dg.cuckoo.admin.service.ProjectInfoServer;
import com.dg.cuckoo.common.utils.PageModel;
import com.dg.cuckoo.core.BaseController;
import com.dg.cuckoo.core.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 基本资料-项目信息
 */
@RestController
@RequestMapping("/basicInformation/projectInfo")

public class ProjectInformation extends BaseController {

    @Autowired
    private ProjectInfoServer projectInfoServer;


    /**
     * 新增
     * @return
     */
    @PostMapping("save")
    public JsonResult<Void> save(BasicProjectDto basicProjectDto, MultipartFile[] file,String [] labels,String [] units) throws Exception {
        projectInfoServer.save(basicProjectDto,file,labels,units);
        return new JsonResult<>(OK);
    }

    /**
     * 删除
     * @param id 项目主键id
     * @return
     */
    @PostMapping("delect/{id}")
    public JsonResult<Void> delect(@PathVariable String id){
        projectInfoServer.delect(id);
        return new JsonResult<>(OK);
    }

    /**
     * 编辑
     * @return
     */
    @PostMapping("update/{id}")
    public JsonResult<Void> update(BasicProjectDto basicProjectDto, MultipartFile[] file,String [] labels,String [] units,@PathVariable String id) throws Exception {
        projectInfoServer.update(basicProjectDto,file,labels,units,id);
        return new JsonResult<>(OK);
    }

    /**
     * 分页
     * @param page 页
     * @param pageSize 页数
     * @return
     */
    @PostMapping("page/{page}/{pageSize}")
    public JsonResult<PageModel> page(@PathVariable Integer page,@PathVariable Integer pageSize){
        PageModel data = projectInfoServer.page(page, pageSize);
        return new JsonResult<>(OK,data);
    }


    /**
     * 点击项目获取信息
     */
    @PostMapping("openInfo/{id}")
    public JsonResult<String> openInfo(@PathVariable String id){
        String data = projectInfoServer.openInfo(id);
        return new JsonResult<>(OK,data);
    }

    /**
     * 新建中点击标签弹出界面(弹出所有一级标签)
     */
    @PostMapping("clickLabelInfo")
    public JsonResult<String> clickLabelInfo(){
        String data = projectInfoServer.clickLabelInfo();
        return new JsonResult<>(OK,data);
    }

    /**
     * 新建中点击一级标签(弹出二级标签)
     */
    @PostMapping("clickTwoLabelInfo")
    public JsonResult<String> clickTwoLabelInfo(String oneLabel){
        String data = projectInfoServer.clickTwoLabelInfo(oneLabel);
        return new JsonResult<>(OK,data);
    }

    /**
     * 新建中点击建设单位按钮弹出界面
     */
    @PostMapping("clickUnitInfo")
    public JsonResult<String> clickUnitInfo(){
        String data = projectInfoServer.clickUnitInfo();
        return new JsonResult<>(OK,data);
    }

    /**
     * 建设单位界面点击包 显示数据
     */
    @PostMapping("clickUnitTreeInfo")
    public JsonResult<String> clickUnitTreeInfo(String unit){
        String data = projectInfoServer.clickUnitTreeInfo(unit);
        return new JsonResult<>(OK,data);
    }

    /**
     * 查询框
     * @param word 关键字
     * @return
     */
    @PostMapping("inquire")
    public JsonResult<List<BasicProjectDto>> inquire(String word){
        List<BasicProjectDto> data = projectInfoServer.inquire(word);
        return new JsonResult<>(OK,data);
    }

}
